/**  
 * Project Name:api-webhook  
 * File Name:EmailClient.java  
 * Package Name:com.example.service.webhook.api  
 * Date:2016年7月19日下午5:17:42  
 * Copyright (c) 2016, yuandong@51dojo.com All Rights Reserved.  
 *  
*/  
  
package com.example.service.webhook.business.alipay.api;

import java.io.IOException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.example.service.webhook.api.MoxieClient;
import com.example.service.webhook.business.alipay.dto.AlipayTradeCategory;
import com.example.service.webhook.business.alipay.dto.AlipayTradeRecord;
import com.example.service.webhook.business.alipay.dto.AlipayUserInfo;
import com.example.service.webhook.business.alipay.dto.AlipayWealth;
import com.example.service.webhook.business.alipay.dto.AlipayYuebaoTradeInfo;

import retrofit2.Call;
import retrofit2.Response;

/**
 * 支付宝client
 * ClassName: AlipayClient    
 * date: 2016年9月9日 上午11:48:18   
 * @author yuandong  
 * @version   
 * @since JDK 1.6
 */
@Component
public class AlipayClient extends MoxieClient{
	
	 private AlipayApi api;
	 
	 @Autowired
	public AlipayClient(@Value("${moxie.api.baseUrl}") String apiBaseUrl,
            @Value("${moxie.api.token}") String apiToken) {
		super(apiBaseUrl, apiToken);  
		api = retrofit.create(AlipayApi.class);
	}

	private static final Logger LOGGER = LoggerFactory.getLogger(AlipayClient.class);
	
	
	public AlipayUserInfo getUserInfo(String taskId) throws IOException {
        Call<AlipayUserInfo> call = api.getBaseInfo(taskId);
        Response<AlipayUserInfo> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("alipay getBaseInfo, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }
	
	public List<AlipayTradeRecord> getTradeInfo(String taskId) throws IOException {
        Call<List<AlipayTradeRecord>> call = api.getTradeInfo(taskId);
        Response<List<AlipayTradeRecord>> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("alipay getTradeInfo, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }
	
	
	public AlipayWealth getWealth(String taskId) throws IOException {
        Call<AlipayWealth> call = api.getWealth(taskId);
        Response<AlipayWealth> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("alipay getWealth, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }
	
	
//	public List<AlipayYuebaoTradeInfo> getYuebaotradeinfo(String taskId) throws IOException {
//        Call<List<AlipayYuebaoTradeInfo>> call = api.getYuebaotradeinfo(taskId);
//        Response<List<AlipayYuebaoTradeInfo>> response = call.execute();
//        if (response.code() == 200) {
//            return response.body();
//        } else {
//            LOGGER.info("alipay getYuebaotradeinfo, status:{}, message:{}", response.code(), response.message());
//        }
//        return null;
//    }
//	
//	
//	public List<AlipayTradeCategory> getTradecategory(String taskId) throws IOException {
//        Call<List<AlipayTradeCategory>> call = api.getTradecategory(taskId);
//        Response<List<AlipayTradeCategory>> response = call.execute();
//        if (response.code() == 200) {
//            return response.body();
//        } else {
//            LOGGER.info("alipay getTradecategory, status:{}, message:{}", response.code(), response.message());
//        }
//        return null;
//    }
	
	
}
  
